package com.coffeeloversupportlibrary.coffeelover.networktest;

import android.util.Log;

import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.Article;
import com.coffeeloversupportlibrary.coffeelover.domain.article.entity.OriginData;
import com.coffeeloversupportlibrary.coffeelover.networktest.entity.Articles;
import com.coffeeloversupportlibrary.core.base.BaseViewModel;
import com.coffeeloversupportlibrary.core.base.livadata.SingleLiveEvent;
import com.coffeeloversupportlibrary.core.data.DataRepository;

import java.util.List;

/**
 * @author puyv
 * @createTime 2021/11/13 12:38
 * @projectName CoffeeLoverSupportLibrary
 * @className NetViewModel.java
 * @description TODO
 */
public class NetViewModel extends BaseViewModel<NetModel> {
    private SingleLiveEvent<String> responseInfo=new SingleLiveEvent<String>();
    private List<Article> list;

    public SingleLiveEvent<String> getResponseInfo(){
        return this.responseInfo;
    }

    public void start(){

         mModel.netWorkTest(new NetModel.ViewModelCallBack<Articles>() {
             @Override
             public void onSuccess(Articles articles) {
                 String info=articles.getArticleInfo();
                 responseInfo.setValue(info);
             }

             @Override
             public void Failure() {

             }
         });
    }

    public List<Article> articleList(){
        mModel.netArticleList(new NetModel.ViewModelCallBack<List<Article>>() {
            @Override
            public void onSuccess(List<Article> articles) {
               if(null!=articles){
                  for(Article article:articles){
                      Log.e("Tag",article.getArticleId());
                  }
               }
            }

            @Override
            public void Failure() {

            }
        });
        return list;
    }
    @Override
    protected void setModel() {
        mModel=new NetModel(DataRepository.getInstance());
    }
}
